//
//  RainScrollView.m
//  UI09_作业
//
//  Created by dllo on 16/6/16.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "RainScrollView.h"

@implementation RainScrollView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

- (void)createSubView{
    self.pagingEnabled = YES;
    self.showsVerticalScrollIndicator = NO;
    self.showsHorizontalScrollIndicator = NO;
    self.bounces = NO;
}
- (void)addPhoto:(NSArray<UIImage *> *)photoArray{
    for (NSInteger i = 0; i < photoArray.count; i++) {
        UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(i * CGRectGetWidth(self.bounds), 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds))];
        scroll.minimumZoomScale = 0.5;
        scroll.maximumZoomScale = 2;
        scroll.delegate = self;
        [self addSubview:scroll];
    
        self.contentSize = CGSizeMake(photoArray.count * CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds));
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds))];
        imageView.image = [photoArray objectAtIndex:i];
        [scroll addSubview:imageView];
        [imageView release];
        
        
    }
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    return scrollView.subviews.firstObject;
}
@end
